<admintpl file="header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('message/index')}">自动回复管理</a></li>
			<li class="active"><a href="{:U('message/add')}">添加自动回复</a></li>
		</ul>
		<form class="form-horizontal js-ajax-form" action="{:U('message/add_post')}" method="post" enctype="multipart/form-data">
			<div class="tabbable">
		        <div class="tab-content">
		          <div class="tab-pane active" id="A">
						<fieldset>							
							<div class="control-group">
								<label class="control-label">关键词</label>
								<div class="controls">
									<input type="text" name="name" value=""><span class="form-required">*</span>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">回复的消息类型</label>
								<div class="controls">
									<select name="type" id="selecthref">
										<option value="1">文本消息</option>
										<option value="2">图文消息</option>
									</select>
								</div>
							</div>
							
							<div class="content">
								<div class="control-group ">
									<label class="control-label">内容</label>
									<div class="controls">
										<textarea name="description" rows="5" cols="57"></textarea>
									</div>								
								</div>
								
							</div>
							<div class="control-group">
								<a href="javascript:;" class="btn add-gray" >增加图文</a>
								<span class="inum" style="display:none;">1</span>
							</div>
						</fieldset>
		          </div>
		         		          
		        </div>
		    </div>
		    <div class="form-actions">
		     	<button class="btn btn-primary js-ajax-submit" type="submit">{:L('ADD')}</button>
		      	<a class="btn" href="javascript:history.back(-1);">{:L('BACK')}</a>
		    </div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>	
	<script type="text/javascript">
		$('#selecthref').live("change",function(){
			var _val = $(this).val();
			if(_val == 2){
				var _html;
				_html = '<div class="text_pic"><div class="control-group"><label class="control-label">图文<span class="num"></span></label></div><div class="control-group"><label class="control-label">标题</label><div class="controls"><input type="text" name="title" value=""></div></div><div class="control-group"><label class="control-label">描述</label><div class="controls"><input type="text" name="description" value=""><span class="form-required">（只有一条图文时显示）</span></div></div><div class="control-group"><label class="control-label">图片</label><div class="controls"><input type="hidden" name="thumb" id="thumb" value=""> <a href="javascript:upload_one_image('+"'图片上传'"+','+"'#thumb'"+');"><img src="__TMPL__Public/assets/images/default-thumbnail.png" id="thumb-preview" width="135" style="cursor:hand"></a> <input type="button" class="btn btn-small" onclick="return $(&quot;#thumb-preview&quot;).attr(&quot;src&quot;,&quot;__TMPL__Public/assets/images/default-thumbnail.png&quot;),$(&quot;#thumb&quot;).val(&quot;&quot;),!1" value="取消图片"></div></div><div class="control-group"><label class="control-label">url</label><div class="controls"><input type="text" name="url" value=""></div></div></div>';
				$('.content').html(_html);
				$('.add-gray').show();
			}else{
				var _htmltext;
				_htmltext = '<div class="control-group "><label class="control-label">内容</label><div class="controls"><textarea name="description" rows="5" cols="57"></textarea></div></div>';
				$('.content').html(_htmltext);
				$('.add-gray').hide();
			}
		});
	</script>
	<script type="text/javascript">
		$('.tab-pane').on('click','.add-gray',function(){			
			var _num = $('.text_pic').index()+2;
			//thumb+自增
			var inum = $('.inum').text();
			inum++;
			$('.inum').text(inum);
			var _html;
				_html = '<div class="text_pic"><div class="control-group"><label class="control-label">图文<span class="num">'+_num+'</span></label><div class="controls"><a href="javascript:;" title="删除" class="remove"><i class="fa fa-times-circle"></i></a></div></div><div class="control-group"><label class="control-label">标题</label><div class="controls"><input type="text" class="title" name="title'+_num+'" value=""></div></div><div class="control-group"><label class="control-label">描述</label><div class="controls"><input type="text" class="description" name="description'+_num+'" value=""><span class="form-required">（只有一条图文时显示）</span></div></div><div class="control-group"><label class="control-label">图片</label><div class="controls"><input type="hidden" class="thumb" name="thumb'+_num+'" id="thumb'+inum+'" value=""> <a href="javascript:upload_one_image('+"'图片上传'"+','+"'#thumb"+inum+"'"+');"><img src="__TMPL__Public/assets/images/default-thumbnail.png" id="thumb'+inum+'-preview" width="135" style="cursor:hand"></a> <input type="button" class="btn btn-small" onclick="return $(&quot;#thumb'+inum+'-preview&quot;).attr(&quot;src&quot;,&quot;__TMPL__Public/assets/images/default-thumbnail.png&quot;),$(&quot;#thumb'+inum+'&quot;).val(&quot;&quot;),!1" value="取消图片"></div></div><div class="control-group"><label class="control-label">url</label><div class="controls"><input type="text" name="url'+_num+'"  value=""></div></div></div>';
			$('.content').append(_html);
			
		});
	</script>
	<script type="text/javascript">
		$('.tab-pane').on('click','.remove',function(){
			
			
			$(this).parent().parent().parent().remove();
			var _num = $('.text_pic').length;			
			for(var i=1;i<_num;i++){
				$('.text_pic:eq('+i+') .num').text(i+1);	
				var j = i+1;
				$('.text_pic:eq('+i+') .title').attr('name','title'+j);
			}
		});
	</script>
</body>
</html>